﻿using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using PlatformUW.Entities;


namespace PlatformUW.EntityFramework.Mappings
{
    public class CharacterMap : IEntityTypeConfiguration<Characters>
    {
        public void Configure(EntityTypeBuilder<Characters> builder)
        {
            builder.ToTable("Characters");
            builder.Property(character => character.NickName).HasMaxLength(20);
            builder.Property(character => character.Classes).HasMaxLength(20);
            builder.HasIndex(character => character.NickName).IsUnique();

            builder.HasOne(character => character.player)
                   .WithMany(player => player.characters)
                   .HasForeignKey(character => character.PlayerId)
                   .OnDelete(DeleteBehavior.Cascade);
        }
    }
}
